﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace SectorsDesigner
{
    public partial class TextureChooserDialog : Form
    {
        public TextureChooserControl Chooser;
        public Dictionary<string, Texture2D> Library;
        public SectorsMapMakerControl Designer;
        public Texture2D[] Textures;
        public string[] Keys;
        public TextureChooserDialog(SectorsMapMakerControl designer)
        {
            Designer = designer;
            Library = Designer.Textures ;
            Textures = Library.Values.ToArray();
            Keys = Library.Keys.ToArray();
            InitializeComponent();
            Chooser = new TextureChooserControl(this, Designer);
            
            Chooser.SuspendLayout();
            this.panel1.SuspendLayout();
            Chooser.MouseClick += new MouseEventHandler(Chooser_MouseClick);
            Chooser.MouseMove += new MouseEventHandler(Chooser_MouseMove);
            Chooser.MouseDown += new MouseEventHandler(Chooser_MouseDown);
            Chooser.Resize += new EventHandler(Chooser_Resize);
            Chooser.Dock = DockStyle.Fill;
            panel1.Controls.Add(Chooser);
            panel1.ResumeLayout(false);
            Chooser.ResumeLayout(false);
            panel1.PerformLayout();
            Chooser.Show();
            Chooser.Size = new Microsoft.Xna.Framework.Point(panel1.Width, panel1.Height);




            Application.Idle += delegate { hScrollBar1.Minimum = 0; hScrollBar1.Maximum = Keys.Length - Chooser.ThumbsCount; Chooser.Invalidate(); };
        }

        private void SelectButton_Click(object sender, EventArgs e)
        {
            
        }

        void Chooser_Resize(object sender, EventArgs e)
        {
            Chooser.Size = new Microsoft.Xna.Framework.Point(panel1.Width, panel1.Height);
        }

        void Chooser_MouseDown(object sender, MouseEventArgs e)
        {
            //throw new NotImplementedException();
        }

        void Chooser_MouseMove(object sender, MouseEventArgs e)
        {
            Chooser.MousePosition = new Vector2(e.X, e.Y);
        }

        void Chooser_MouseClick(object sender, MouseEventArgs e)
        {
            //throw new NotImplementedException();
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            Chooser.FirstIndex = (int)MathHelper.Clamp(hScrollBar1.Value, 0,Keys.Length - Chooser.ThumbsCount);
        }

        private void TextureChooserDialog_Resize(object sender, EventArgs e)
        {
            Chooser.Invalidate();
        }
    }
}
